//
//  UIButton+myFont.m
//  BeidouMall
//
//  Created by qie on 16/5/11.
//  Copyright © 2016年 qie. All rights reserved.
//

#import "UIButton+myFont.h"

@implementation UIButton (myFont)

+ (void)load
{
    Method imp = class_getInstanceMethod([self class], @selector(initWithCoder:));
    Method myImp = class_getInstanceMethod([self class], @selector(myInitWithCoder:));
    method_exchangeImplementations(imp, myImp);
}

- (id)myInitWithCoder:(NSCoder*)aDecode
{
    [self myInitWithCoder:aDecode];
    if (self) {
        CGFloat fontSize = self.titleLabel.font.pointSize;
        if ([[BDAccountManagerModel shareInstance].langage isEqualToString:@"zang"]) {
            fontSize = fontSize - 2;
            self.titleLabel.font = [UIFont fontWithName:@"Bzdbt" size:fontSize];
        } else {
            self.titleLabel.font = [UIFont systemFontOfSize:fontSize];
        }
    }
    return self;
}

@end

@implementation UILabel (myFont)

+ (void)load
{
    Method imp = class_getInstanceMethod([self class], @selector(initWithCoder:));
    Method myImp = class_getInstanceMethod([self class], @selector(myInitWithCoder:));
    method_exchangeImplementations(imp, myImp);
}

- (id)myInitWithCoder:(NSCoder*)aDecode
{
    [self myInitWithCoder:aDecode];
    if (self) {
        CGFloat fontSize = self.font.pointSize;
        if ([self isKindOfClass:[BDLabel class]]) {
            
        } else {
            if ([[BDAccountManagerModel shareInstance].langage isEqualToString:@"zang"]) {
                fontSize = fontSize - 4.0;
                if ([self.font.fontName isEqualToString:@".SFUIText-Bold"]) {// 字体加粗
                    self.font = [UIFont fontWithName:@"BZDHT" size:fontSize];
                } else {
                    self.font = [UIFont fontWithName:@"Bzdbt" size:fontSize];
                }
            } else {
                if ([self.font.fontName isEqualToString:@".SFUIText-Bold"]) {// 字体加粗
                    self.font = [UIFont boldSystemFontOfSize:fontSize];
                } else {
                    self.font = [UIFont systemFontOfSize:fontSize];
                }
            }
        }
    }
    return self;
}

@end

@implementation UITextField (myFont)

+ (void)load
{
    Method imp = class_getInstanceMethod([self class], @selector(initWithCoder:));
    Method myImp = class_getInstanceMethod([self class], @selector(myInitWithCoder:));
    method_exchangeImplementations(imp, myImp);
}

- (id)myInitWithCoder:(NSCoder*)aDecode
{
    [self myInitWithCoder:aDecode];
    if (self) {
        CGFloat fontSize = self.font.pointSize;
        if ([[BDAccountManagerModel shareInstance].langage isEqualToString:@"zang"]) {
            fontSize = fontSize - 2;
            [self setValue:[UIFont fontWithName:@"Bzdbt" size:fontSize] forKeyPath:@"_placeholderLabel.font"];
        } else {
            [self setValue:[UIFont systemFontOfSize:fontSize] forKeyPath:@"_placeholderLabel.font"];
        }
    }
    return self;
}

@end

@implementation UITextView (myFont)

+ (void)load
{
    Method imp = class_getInstanceMethod([self class], @selector(initWithCoder:));
    Method myImp = class_getInstanceMethod([self class], @selector(myInitWithCoder:));
    method_exchangeImplementations(imp, myImp);
}

- (id)myInitWithCoder:(NSCoder*)aDecode
{
    [self myInitWithCoder:aDecode];
    if (self) {
        CGFloat fontSize = self.font.pointSize;
        if ([self isKindOfClass:[BDTextView class]]) {
            
        } else {
            if ([[BDAccountManagerModel shareInstance].langage isEqualToString:@"zang"]) {
                fontSize = fontSize - 2;
                self.font = [UIFont fontWithName:@"Bzdbt" size:fontSize];
            } else {
                self.font = [UIFont systemFontOfSize:fontSize];
            }
        }
    }
    return self;
}

@end
